package function;

import java.util.Scanner;

//键盘录入分数求平均数
public class fun4 {
    public static void main(String[] args) {
        int[] arr = getScopeList(4);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        int max = getMaxOrMin(arr,true);
        int min = getMaxOrMin(arr,false);
        System.out.println("最大值为："+max);
        System.out.println("最小值为："+min);
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println(sum);
        System.out.println(sum - max - min);
        System.out.println(arr.length-2);
        System.out.println("平均值为："+(sum - max - min) / (arr.length-2));
    }

    public static int[] getScopeList(int number) {
        int[] arr = new int[number];
        for (int i = 0; i < number;) {
            System.out.println("请输入成绩：");
            Scanner sc = new Scanner(System.in);
            int score = sc.nextInt();
            if(score>=0 && score<=100) {
                arr[i] = score;
                //满足条件 i++
                i++;
            }
            else {
                System.out.println("输入0-100的分数，请重新输入：");
            }

        }
        return arr;
    }

    public static int getMaxOrMin(int [] arr,boolean flag) {
        int temp = arr[0];
        for (int i = 0; i < arr.length; i++) {
            boolean b = flag ? arr[i] > temp : arr[i] < temp;
            if(b) {
                temp = arr[i];
            }
        }
        return temp;
    }
}
